<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String id = request.getParameter("id") == null ? "" : request.getParameter("id");
    boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>

<html>
	<head>
		<title><%=isAdd?"新建请假单":"编辑请假单" %></title>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
	</head>
	<script type="text/javascript">	
	
	jQuery(document).ready(function() {
		jQuery("#searchValue").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
	   	}); 
		jQuery("#type_id").combotree({
			url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=10',
			method:'POST',
			animate:true,
			lines:true
		});
		var adminId="";
		var adminName="";
		if('<%=flag%>' == '1'){
			jQuery('#leave').form({
				onLoadSuccess:function(data){
					adminId=data.person_id;
					adminName=data.person_name;
				}
			});
			jQuery('#leave').form("load",'<%=contextPath %>/springMVC/oa/getLeaveById?id=<%=id%>');
	}
	jQuery('#person_id').combogrid({
		title:'人员选择',
		mode:"remote",
		loadMsg:'正在加载数据，请稍后......',
		panelWidth:550,
		panelHeight:400,
		url:"<%=contextPath%>/springMVC/group/listPageUser",
		idField:"id",
		textField:"truename",
		rownumbers:true,
		fitColumns:true,
		columns: [[
			{field:'id',hidden:true},
			{field:'deptId',hidden:true},
			{field:'truename',title:'姓名',width:100},
			{field:'deptName',title:'所属部门',width:100},
			{field:'privName',title:'角色',width:100}
		]],
		toolbar:"#tb",
		pageSize:10,
		pageList:[10,50,100],  
		pagination:true,
		onChange:function(){
			var row = jQuery('#person_id').combogrid("grid").datagrid('getSelected');
			if(row != null){
				jQuery('#dept_id').val(row.deptId);
				jQuery('#dept_name').val(row.deptName);
				jQuery('#person_name').val(row.truename);

			}
		},
		onLoadSuccess:function(rtJson){
			var row = jQuery('#person_id').combogrid("grid").datagrid('getSelected');
			if(row != null){
				jQuery('#dept_id').val(row.deptId);
				jQuery('#dept_name').val(row.deptName);
			}
			jQuery('#person_id').combogrid('setValue',adminId);
			jQuery('#person_id').combogrid('setText',adminName);
			jQuery('#person_name').val(adminName);
		}
	});
	jQuery("#p_dept_id").combotree({
		url:'<%=contextPath %>/springMVC/group/listDepartment',
		method:'POST',
		animate:true,
		lines:true,
		onChange:function(){
			doSearch();
		}
	});
	});
	function doSubmit(obj){
		$("#leave").form('submit',{
			url:"<%=contextPath %>/springMVC/oa/<%=isAdd ? "addLeave" : "updateLeave?id=" + id%>",
			onSubmit:function(){
				var isValid = $(this).form('validate');
				if(isValid){
					$(obj).hide();
				}
				return isValid;
			},
			success:function(rtJson){
				rtJson = eval('(' + rtJson + ')'); 
				if (rtJson.rtState == '0'){
					eval('window.opener.<%=callback%>();');
					window.close();
				}else{
					$(obj).show();
					warningInfo(rtJson.rtMsrg);
				}
			}
		});
	}
	function doSearch() {
		var dept_id = jQuery('#p_dept_id').combotree('getValue');
		var searchValue = jQuery('#searchValue').val();
		jQuery('#person_id').combogrid("grid").datagrid('load', {
			searchValue : searchValue,
			dept_id:dept_id
		});
	}
	</script>
	<body>
		<form id="leave" method="POST">
		<div style="width:90%;padding-left:50px;margin-top:50px" align="center">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
				<tr>
					<td align="right" class="td1" nowrap>请假人：</td>
					<td class="td2" nowrap >
					<input type="text" id="person_id" name="person_id" data-options="required:true">
					<input type="hidden" id="person_name" name="person_name"  />
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>所属部门：</td>
					<td class="td2" nowrap  >
						<input  id="dept_name" name="dept_name" readOnly />
						<input type="hidden" id="dept_id" name="dept_id"  />
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>类别：</td>
					<td class="td2" nowrap  >
						<input  id="type_id" name="type_id" class="easyui-combotree"  data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						请假时间：
					</td>
					<td class="td2" nowrap >
						<input id="leaveTime" name="leaveTime"  class="easyui-datebox" data-options="required:true"/>
					</td>
				</tr>
				<tr id="finance_in_tr">
					<td align="right"  nowrap class="td1">
						销假时间：
					</td>
					<td class="td2" nowrap >
						<input id="destroyLeaveTime" name="destroyLeaveTime" class="easyui-datebox" data-options="required:true"/>
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						请假原因：
					</td>
					<td class="td2" nowrap >
							<textarea id="reason" name="reason" style="height:100%;width:99%" rows="6"></textarea>
					</td>
				</tr>
				<tr>
					<td align="right" nowrap class="td1">
					</td>
					<td  nowrap colspan="5">
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">保存</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
					</td>
				</tr>
				
 			</table>
		</div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
		</form>
	</body>
</html>
